﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region RPTDeviceUsing

        public List<tb_RPT_DeviceUsing> GetAllRPTDeviceUsing()
        {

            var query = (from obj in this.tb_RPT_DeviceUsings
                         where obj.IsDelete == 0
                         select obj).ToList();

            return query; 
        }

        public List<tb_RPT_DeviceUsing> GetRPTDeviceUsingByDeviceId(int deviceId)
        {

            var query = (from obj in this.tb_RPT_DeviceUsings
                         where obj.IsDelete == 0 && obj.DeviceId == deviceId
                         select obj).ToList();

            return query; 
        }

        public List<tb_RPT_DeviceUsing> GetRPTDeviceUsingByUsingDate(DateTime UsingDate1, DateTime UsingDate2)
        {

            var query = (from obj in this.tb_RPT_DeviceUsings
                         where obj.IsDelete == 0 && obj.UsingDate >= UsingDate1 && obj.UsingDate <= UsingDate2
                         select obj).ToList();

            return query;
        }
       

        public List<tb_RPT_DeviceUsing> GetRPTDeviceUsingByTester(string tester)
        {

            var query = (from obj in this.tb_RPT_DeviceUsings
                         where obj.IsDelete == 0 && obj.Tester == tester
                         select obj).ToList();

            return query;
        }

        public tb_RPT_DeviceUsing GetRPTDeviceUsingById(int id)
        {
            return this.tb_RPT_DeviceUsings.SingleOrDefault(tb_RPT_DeviceUsings => tb_RPT_DeviceUsings.Id == id);
        }

        public void CreateRPTDeviceUsing(tb_RPT_DeviceUsing entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_RPT_DeviceUsings.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyRPTDeviceUsing(tb_RPT_DeviceUsing entity)
        {
            tb_RPT_DeviceUsing instance = this.tb_RPT_DeviceUsings.SingleOrDefault(p => p.Id == entity.Id);
            instance.DeviceId = entity.DeviceId;
            instance.UsingDate = entity.UsingDate;
            instance.StartDate = entity.StartDate;
            instance.EndDate = entity.EndDate;
            instance.Status = entity.Status;
            instance.Tester = entity.Tester;  

            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }
        public void DeleteRPTDeviceUsing(tb_RPT_DeviceUsing entity)
        {
            tb_RPT_DeviceUsing deleteEntity = tb_RPT_DeviceUsings.SingleOrDefault(p => p.Id == entity.Id);
            tb_RPT_DeviceUsings.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }

}
